package com.szrt.department.service.impl;

import com.szrt.department.dao.DepartmentDao;
import com.szrt.department.dao.impl.DepartmentDaoImpl;
import com.szrt.department.entity.DepartmentEntity;
import com.szrt.department.service.DepartmentService;

public class DepartmentServiceImpl implements DepartmentService {

	private DepartmentDao dao = new DepartmentDaoImpl();
	
	@Override
	public int add(DepartmentEntity entity) {
		//1 判断是否有重复的部门名称 或者  重复部门编码
		
		
		/**
		 * 1 有异常      counter = -1
		 * 2 没有重复   counter = 0
		 * 3 重复         counter >0
		 */
		int counter = dao.check(entity);
		
		//2 如果没有重复
		if(counter==0){
			//说明没有重复 直接插入数据
			counter =dao.add(entity);
		}else{
			//说明要不就重复  要不check方法出了异常
			counter = 0;
		}
		
		return counter;
	}

	@Override
	public int delete(Integer departmentCode) {
		
		//先去判断 departmentCode有没有
		return dao.delete(departmentCode);
	}

}
